package org.example.cloud.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.cloud.bean.File;
import org.example.cloud.bean.Folder;

import java.util.Date;
import java.util.List;

@Mapper
public interface FileFolderMapper {


    @Select("SELECT * FROM folder WHERE username = #{username} AND hdfsPath =#{parentPath}")
    List<Folder> findFoldersByUsernameAndPath(String username, String parentPath);

    @Select("SELECT fileId,fileName,typeId,createTime,hdfsPath,fileSize FROM file WHERE owner = #{username} AND hdfsPath = #{parentPath}")
    List<File> findFilesByUsernameAndPath(String username, String parentPath);
    @Select("SELECT typeName FROM fileType WHERE typeId = #{typeId}")
    String findFileTypeById(Integer typeId);
    @Insert("INSERT INTO folder (folderName,hdfsPath, owner,  createdTime) " +
            "VALUES (#{dirName}, #{parentId}, #{hdfsPath}，#{username}, #{createdAt})")
    boolean saveFolder( String dirName,String hdfsPath,String username,  Date createdAt);
    @Select("select folderId from folder where hdfsPath=#{hdfsPath}")
    Integer findParentId(String hdfsPath);

    @Select("select fileId from file where hdfsPath=#{hdfsPath}")
    Integer getFileId(String hdfsPath);
    @Update("UPDATE folder SET status = 0, deletedTime = #{deletedTime} WHERE folderId = #{folderId}")
    boolean moveFolderToTrash(Integer folderId, Date deletedTime);

    @Update("UPDATE file SET status = 0, deletedTime = #{deletedTime} WHERE fileId = #{fileId}")
    boolean moveFileToTrash(Integer fileId, Date deletedTime);
}
